<template>
	<view class="">
		<!-- 头部搜索热区 -->
		<SearchLink />

		<!-- 轮播图 -->
		<swiper indicator-dots autoplay circular indicator-color="rgba(255, 255, 255, .3)" indicator-active-color="#fff">
			<swiper-item v-for="(item,index) in swiperdata" :key="index">
				<image :src="item.image_src"></image>
			</swiper-item>
		</swiper>
		<!-- 导航栏 -->
		<view class="nav">
			<image v-for="(item,index) in catitems" :key="index" :src="item.image_src"></image>
		</view>
		<!-- 楼层 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(floor,findex) in floordata" :key="findex">
				<image :src="floor.floor_title.image_src"></image>
				<view class="product-list">
					<image :src="floor.product_list[0].image_src"></image>
					<view class="right">
						<!-- 第一个不需要渲染 -->
						<block v-for="(item,index) in floor.product_list" :key="index">
							<image v-if="index" :src="item.image_src"></image>
						</block>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// 引入SearchLink组件
	import SearchLink from '@/components/SearchLink.vue'
	export default {
		components: {
			// 组件名:具体的某个组件
			// SearchLink:SearchLink 
			SearchLink
		},
		data() {
			return {
				// 轮播图的数据
				swiperdata: [],
				// 导航栏的数据
				catitems: [],
				// 楼层数据
				floordata: []
			}
		},
		// 尽早发请求
		onLoad() {
			this.getSwiperdata()
			this.getCatitems()
			this.getFloordata()
		},
		methods: {
			async getSwiperdata() {
				// 这个data就是	resolve(message)里面message
				try{
					this.swiperdata = await this.$request({
						url: '/api/public/v1/home/swiperdata'
					})
				}catch(err){
					
				}
			},
			async getCatitems() {
				this.catitems = await this.$request({
					url: '/api/public/v1/home/catitems'
				})
			},
			async getFloordata() {
				this.floordata = await this.$request({
					url: '/api/public/v1/home/floordata'
				})
			}
		}
	}
</script>

<style lang="less">
	swiper {
		height: 340rpx;

		image {
			height: 100%;
			width: 100%;
		}
	}

	.nav {
		height: 194rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;

		image {
			width: 128rpx;
			height: 140rpx;
		}
	}

	.floor-item {
		>image {
			height: 88rpx;
			width: 100%;
		}

		.product-list {
			display: flex;
			margin: 20rpx 0 0 17rpx;

			>image {
				width: 232rpx;
				height: 382rpx;
			}

			.right {
				// 占满剩下的宽度
				flex: 1;
				display: flex;
				flex-wrap: wrap;

				image {
					width: 232rpx;
					height: 188rpx;
					margin: 0 0 10rpx 10rpx;
				}
			}
		}
	}
</style>
